Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix external js updates to multi-selects #1070

Closed
wants to merge 1 commit into from

Conversation

tjarratt
Copy link

@tjarratt tjarratt commented Mar 6, 2013

I ran into some issues where updated multi selects from external
javascript (using $(select).trigger("liszt:updated") would frequently
get out of state because the #choices variable on the Chosen object
was no longer the same as the actual number of options selected.

Instead of having a global variable on the chosen jquery object
(which is relatively fragile because of external changes to the
select element), just calculate it as needed. It's not called often
and this is a fairly fast lookup for jquery and prototype, so I think
this is a safe change.

This is my first pull request on a js project using coffeescript, so
any feedback is welcome. I'm already using this patch in a production
setting, so if you'd like I could describe the actual use case that produced
this error condition, or provide a minimal reproduction of the issue but
in my opinion this is a fairly clear change that resolves some of the bugs
one would encounter using chosen with ember.js, or another UI heavy
library where updates to the select element are not always through user
interaction.

I ran into some issues where updated multi selects from external
javascript would frequently get out of state because the .choices
variable on the Chosen object was no longer the same as the actual
number of options selected.

Instead of having a global variable on the chosen jquery object
(which is relatively fragile because of external changes to the
select element), just calculate it as needed. It's not called often
and this is a fairly fast lookup for jquery and prototype, so I think
this is a safe change.
@pfiller
Copy link
Contributor

pfiller commented Apr 26, 2013

Thanks @tjarratt

I was nervous about the way selected options were being queried, so I did some testing. It turns out that looping through the raw javascript select object's options is much faster, so I moved the counting method to the abstractChosen method.

Your commit has been added to this PR: #1171. Please let me know if this still solves your issue and any other thoughts you might have.

@pfiller pfiller closed this Apr 26, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants